//
//  DBJTagsView.m
//  DBJ
//
//  Created by Captain_czq on 16/11/15.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "DBJTagsView.h"
#import "BtnView.h"
#import <Masonry.h>
@implementation DBJTagsView


//-(void)awakeFromNib{
//    [super awakeFromNib];
//    
//    [self creatTag];
//}

-(void)dbjSetupSubviews{
    
//    [self creatTagWith:self.tags];

}
#pragma mark -creatTags
-(void)creatTagWith:(NSArray *)tags{
    //添加接口
//    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 150, [UIScreen mainScreen].bounds.size.width, 300)];
   self.backgroundColor = [UIColor whiteColor];
    int width = 0;
    int height = 0;
    int number = 0;
    int han = 0;
    
//    NSArray *titleArr = @[@"医德高尚",@"非常耐心",@"日了狗了",@"嘻嘻嘻",@"嘻嘻是",@"死代售点"];
    //创建button
    for (int i = 0; i < tags.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = 300 + i;
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        
        CGSize titleSize = [tags[i] boundingRectWithSize:CGSizeMake(999, 25) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
        titleSize.width += 5;
        
        //自动的折行
        han = han +titleSize.width+10;
        if (han > [[UIScreen mainScreen]bounds].size.width) {
            han = 0;
            han = han + titleSize.width;
            height++;
            width = 0;
            width = width+titleSize.width;
            number = 0;
            button.frame = CGRectMake(10, 10 +50*height, titleSize.width, 40);
        }else{
            button.frame = CGRectMake(width+10+(number*10), 10 +50*height, titleSize.width, 40);
            width = width+titleSize.width;
        }
        number++;
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.layer.masksToBounds = YES;
        button.layer.cornerRadius = 10;
        button.backgroundColor = [UIColor lightGrayColor];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button setTitle:tags[i] forState:UIControlStateNormal];
        [self addSubview:button];
    }
}
-(void)setTags:(NSArray *)tags{
    _tags=tags;
    self.backgroundColor = [UIColor clearColor];
    int width = 0;
    int height = 0;
    int number = 0;
    int han = 0;
    
    //    NSArray *titleArr = @[@"医德高尚",@"非常耐心",@"日了狗了",@"嘻嘻嘻",@"嘻嘻是",@"死代售点"];
    //创建button
    for (int i = 0; i < tags.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = 300 + i;
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        
        CGSize titleSize = [tags[i] boundingRectWithSize:CGSizeMake(999, 25) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
        titleSize.width += 5;
        
        //自动的折行
        han = han +titleSize.width+10;
        if (han > [[UIScreen mainScreen]bounds].size.width) {
            han = 0;
            han = han + titleSize.width;
            height++;
            width = 0;
            width = width+titleSize.width;
            number = 0;
            button.frame = CGRectMake(10, 10 +50*height, titleSize.width, 40);
        }else{
            button.frame = CGRectMake(width+10+(number*10), 10 +50*height, titleSize.width, 40);
            width = width+titleSize.width;
        }
        number++;
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.layer.masksToBounds = YES;
        button.layer.cornerRadius = 10;
        button.backgroundColor = [UIColor colorWithRed:100/255.0 green:186/255.0 blue:196/255.0 alpha:1];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button setTitle:tags[i] forState:UIControlStateNormal];
        [self addSubview:button];
    }

}

@end
